package com.xfxplus.m.Module;

import android.app.Activity;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.xfxplus.m.R;
import com.xfxplus.m.dataBean.Userbean;
import com.xfxplus.m.databinding.ItemHolderBinding;

import java.util.List;

import javax.inject.Inject;

import static android.view.LayoutInflater.*;

public class Order_adapter extends Adapter<Order_adapter.orderViewHolder> {

    Activity activity;
    List<Userbean> stringList;

    @Inject
    public Order_adapter(Activity activity,List<Userbean> stringList){
        this.activity=activity;
        this.stringList=stringList;
    }


    @Override
    public orderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        ItemHolderBinding itemHolderBinding=DataBindingUtil.inflate(LayoutInflater.from(activity), R.layout.item_holder,parent, false);
        orderViewHolder holder =new orderViewHolder(itemHolderBinding);
        return holder;
    }

    @Override
    public void onBindViewHolder(orderViewHolder holder, int position) {
//            holder.textView.setText(stringList.get(position));
        holder.itemHolderBinding.setUser(stringList.get(position));
        holder.itemHolderBinding.executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return stringList.size();
    }

    public void  addDate(List<Userbean> userbean){
        stringList.addAll(userbean);
        this.notifyDataSetChanged();
    }

    public void reDate(List<Userbean> userbean){
        stringList.clear();
        stringList.addAll(userbean);
        this.notifyDataSetChanged();
    }

    class orderViewHolder extends RecyclerView.ViewHolder{
        ItemHolderBinding itemHolderBinding;
        public orderViewHolder(ItemHolderBinding itemHolderBinding) {
            super(itemHolderBinding.getRoot());
            this.itemHolderBinding=itemHolderBinding;
        }
    }
}
